package com.example.chapter03;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.chapter03.util.DateUtil;

public class ButtonClickActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_click);
        TextView tv_click_single = findViewById(R.id.tv_click_single);
        Button btn_click_single= findViewById(R.id.btn_click_single);
        btn_click_single.setOnClickListener(new MyOnClickListener(tv_click_single));

        TextView tv_long_click = findViewById(R.id.tv_long_click); 
        Button btn_long_click=findViewById(R.id.btn_long_click);
        btn_long_click.setOnLongClickListener(view -> {
            String desc = String.format("%s 您点击了按钮： %s", DateUtil.getNowTime(), ((Button) view).getText());
            tv_long_click.setText(desc);
            return false;
        });
    }
    static class MyOnClickListener implements View.OnClickListener{

        private final TextView tvClickSingle;

        public MyOnClickListener(TextView tvClickSingle) {
            this.tvClickSingle=tvClickSingle;
        }

        @Override
        public void onClick(View view) {
            String desc = String.format("%s 您点击了按钮： %s", DateUtil.getNowTime(), ((Button) view).getText());
            tvClickSingle.setText(desc);
        }
    }
}